package com.example.homework.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.homework.R;
import com.example.homework.bean.FocusData;

import java.util.ArrayList;
import java.util.List;

public class FocusAdapter extends RecyclerView.Adapter<FocusAdapter.FocusViewHolder> {
    private Context context1;
    private ArrayList<FocusData> list1;

    public FocusAdapter(Context context1, ArrayList<FocusData> list) {
        this.context1 = context1;
        this.list1 = list;
    }

    @Override
    public FocusViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context1).inflate(R.layout.item_focus,parent,false);
        FocusViewHolder focusViewHolder = new FocusViewHolder(view);
        return focusViewHolder;
    }

    @Override
    public void onBindViewHolder(FocusViewHolder holder, int position) {
        holder.icon1.setImageResource(list1.get(position).getIcon1());
        holder.nickname.setText(list1.get(position).getNickname());
        holder.message.setText(list1.get(position).getMessage());
        holder.time.setText(list1.get(position).getTime());

    }

    @Override
    public int getItemCount() {
        return list1.size();
    }

    public static final class FocusViewHolder extends RecyclerView.ViewHolder {
        ImageView icon1;
        TextView nickname,message,time;
        public FocusViewHolder(View itemView) {
            super(itemView);
            icon1 = itemView.findViewById(R.id.icon1);
            nickname = itemView.findViewById(R.id.nickname);
            message = itemView.findViewById(R.id.message);
            time = itemView.findViewById(R.id.time);
        }
    }
}
